API Documentation
Public Member Functions | List of all members
nkMaths::Vector Class Reference

A 4-component vector class, with floats. More...

Inheritance diagram for nkMaths::Vector:
nkMaths::Quaternion

Public Member Functions

 Vector ()
 
 Vector (float x, float y)
 
 Vector (float x, float y, float z)
 
 Vector (float x, float y, float z, float w)
 
 Vector (const Vector &other)
 
 Vector (const IVector &other)
 
 Vector (const DirectX::XMVECTOR &value)
 
 ~Vector ()
 
float getX () const
 
float getY () const
 
float getZ () const
 
float getW () const
 
DirectX::XMVECTOR getValues () const
 
void setX (float value)
 
void setY (float value)
 
void setZ (float value)
 
void setW (float value)
 
void addX (float value)
 
void addY (float value)
 
void addZ (float value)
 
void addW (float value)
 
void multX (float value)
 
void multY (float value)
 
void multZ (float value)
 
void multW (float value)
 
void normalizeAsVec2 ()
 
Vector getNormalizedAsVec2 () const
 
void normalizeAsVec3 ()
 
Vector getNormalizedAsVec3 () const
 
void normalizeAsVec4 ()
 
Vector getNormalizedAsVec4 () const
 
float dotProductAsVec2 (const Vector &other) const
 
float dotProductAsVec3 (const Vector &other) const
 
float dotProductAsVec4 (const Vector &other) const
 
void setAsCrossVec2 (const Vector &other)
 
Vector getCrossVec2 (const Vector &other)
 
void setAsCrossVec3 (const Vector &other)
 
Vector getCrossVec3 (const Vector &other) const
 
void setAsCrossVec4 (const Vector &other1, const Vector &other2)
 
Vector getCrossVec4 (const Vector &other1, const Vector &other2) const
 
float getLength () const
 
float getLengthSquared () const
 
float getDistanceSquared (const Vector &other) const
 
float getDistance (const Vector &other) const
 
void fromString (const std::string_view &str)
 
Vectoroperator= (const Vector &other)
 
Vectoroperator= (const IVector &other)
 
Vector operator+ (const Vector &other) const
 
void operator+= (const Vector &other)
 
Vector operator- (const Vector &other) const
 
void operator-= (const Vector &other)
 
Vector operator* (const Vector &other) const
 
void operator*= (const Vector &other)
 
Vector operator* (const Quaternion &other) const
 
void operator*= (const Quaternion &other)
 
Vector operator* (const Matrix &mat) const
 
void operator*= (const Matrix &other)
 
Vector operator* (float coeff) const
 
void operator*= (float coeff)
 
Vector operator/ (const Vector &other) const
 
void operator/= (const Vector &other)
 
Vector operator/ (float coeff) const
 
void operator/= (float coeff)
 
bool operator== (const Vector &other) const
 
bool operator!= (const Vector &other) const
 
bool operator< (const Vector &other) const
 
bool operator<= (const Vector &other) const
 
bool operator> (const Vector &other) const
 
bool operator>= (const Vector &other) const
 

Detailed Description

A 4-component vector class, with floats.

Constructor & Destructor Documentation

◆ Vector() [1/7]

nkMaths::Vector::Vector ( )

Default constructor.

◆ Vector() [2/7]

nkMaths::Vector::Vector ( float  x,
float  y 
)

2D constructor.

Parameters
xThe x component to assign.
yThe y component to assign.

◆ Vector() [3/7]

nkMaths::Vector::Vector ( float  x,
float  y,
float  z 
)

3D constructor.

Parameters
xThe x component to assign.
yThe y component to assign.
zThe z component to assign.

◆ Vector() [4/7]

nkMaths::Vector::Vector ( float  x,
float  y,
float  z,
float  w 
)

4D constructor.

Parameters
xThe x component to assign.
yThe y component to assign.
zThe z component to assign.
wThe w component to assign.

◆ Vector() [5/7]

nkMaths::Vector::Vector ( const Vector other)

Copy constructor.

Parameters
otherThe vector to copy from.

◆ Vector() [6/7]

nkMaths::Vector::Vector ( const IVector other)

Copy constructor.

Parameters
otherThe vector to copy from.

◆ Vector() [7/7]

nkMaths::Vector::Vector ( const DirectX::XMVECTOR &  value)

Fill constructor.

Parameters
valueThe XM values.

◆ ~Vector()

nkMaths::Vector::~Vector ( )

Destructor.

Member Function Documentation

◆ getX()

float nkMaths::Vector::getX ( ) const
Returns
The x component.

◆ getY()

float nkMaths::Vector::getY ( ) const
Returns
The y component.

◆ getZ()

float nkMaths::Vector::getZ ( ) const
Returns
The z component.

◆ getW()

float nkMaths::Vector::getW ( ) const
Returns
The w component.

◆ getValues()

DirectX::XMVECTOR nkMaths::Vector::getValues ( ) const
Returns
The values compressed in the DirectXMath structure.
Remarks
Avoid using this function as this will most likely be dropped when the Maths component is created.

◆ setX()

void nkMaths::Vector::setX ( float  value)

Sets the x component.

Parameters
valueThe value to set.

◆ setY()

void nkMaths::Vector::setY ( float  value)

Sets the y component.

Parameters
valueThe value to set.

◆ setZ()

void nkMaths::Vector::setZ ( float  value)

Sets the z component.

Parameters
valueThe value to set.

◆ setW()

void nkMaths::Vector::setW ( float  value)

Sets the w component.

Parameters
valueThe value to set.

◆ addX()

void nkMaths::Vector::addX ( float  value)

Adds to the x component.

Parameters
valueThe value to add.

◆ addY()

void nkMaths::Vector::addY ( float  value)

Adds to the y component.

Parameters
valueThe value to add.

◆ addZ()

void nkMaths::Vector::addZ ( float  value)

Adds to the z component.

Parameters
valueThe value to add.

◆ addW()

void nkMaths::Vector::addW ( float  value)

Adds to the w component.

Parameters
valueThe value to add.

◆ multX()

void nkMaths::Vector::multX ( float  value)

Multiply the x component.

Parameters
valueThe value to multiply.

◆ multY()

void nkMaths::Vector::multY ( float  value)

Multiply the y component.

Parameters
valueThe value to multiply.

◆ multZ()

void nkMaths::Vector::multZ ( float  value)

Multiply the z component.

Parameters
valueThe value to multiply.

◆ multW()

void nkMaths::Vector::multW ( float  value)

Multiply the w component.

Parameters
valueThe value to multiply.

◆ normalizeAsVec2()

void nkMaths::Vector::normalizeAsVec2 ( )

Normalizes the vector, interpreting it as a 2D vector.

◆ getNormalizedAsVec2()

Vector nkMaths::Vector::getNormalizedAsVec2 ( ) const
Returns
A vector corresponding to this vector interpreted as a 2D vector and normalized.

◆ normalizeAsVec3()

void nkMaths::Vector::normalizeAsVec3 ( )

Normalizes the vector, interpreting it as a 3D vector.

◆ getNormalizedAsVec3()

Vector nkMaths::Vector::getNormalizedAsVec3 ( ) const
Returns
A vector corresponding to this vector interpreted as a 3D vector and normalized.

◆ normalizeAsVec4()

void nkMaths::Vector::normalizeAsVec4 ( )

Normalizes the vector, interpreting it as a 4D vector.

◆ getNormalizedAsVec4()

Vector nkMaths::Vector::getNormalizedAsVec4 ( ) const
Returns
A vector corresponding to this vector interpreted as a 4D vector and normalized.

◆ dotProductAsVec2()

float nkMaths::Vector::dotProductAsVec2 ( const Vector other) const

Computes the dot product, interpreting both vectors as 2D vectors.

Parameters
otherThe vector to compute the product with.
Returns
The resulting dot product computed.

◆ dotProductAsVec3()

float nkMaths::Vector::dotProductAsVec3 ( const Vector other) const

Computes the dot product, interpreting both vectors as 3D vectors.

Parameters
otherThe vector to compute the product with.
Returns
The resulting dot product computed.

◆ dotProductAsVec4()

float nkMaths::Vector::dotProductAsVec4 ( const Vector other) const

Computes the dot product, interpreting both vectors as 4D vectors.

Parameters
otherThe vector to compute the product with.
Returns
The resulting dot product computed.

◆ setAsCrossVec2()

void nkMaths::Vector::setAsCrossVec2 ( const Vector other)

Computes and sets in place the cross product, interpreting both vectors as 2D vectors.

Parameters
otherThe vector to compute the product with.

◆ getCrossVec2()

Vector nkMaths::Vector::getCrossVec2 ( const Vector other)

Computes the cross product, interpreting both vectors as 2D vectors.

Parameters
otherThe vector to compute the product with.
Returns
The resulting cross product computed.

◆ setAsCrossVec3()

void nkMaths::Vector::setAsCrossVec3 ( const Vector other)

Computes and sets in place the cross product, interpreting both vectors as 3D vectors.

Parameters
otherThe vector to compute the product with.

◆ getCrossVec3()

Vector nkMaths::Vector::getCrossVec3 ( const Vector other) const

Computes the cross product, interpreting both vectors as 3D vectors.

Parameters
otherThe vector to compute the product with.
Returns
The resulting cross product computed.

◆ setAsCrossVec4()

void nkMaths::Vector::setAsCrossVec4 ( const Vector other1,
const Vector other2 
)

Computes and sets in place the cross product, interpreting all vectors as 4D vectors.

Parameters
other1The vector to compute the product with.
other2The vector to compute the product with.

◆ getCrossVec4()

Vector nkMaths::Vector::getCrossVec4 ( const Vector other1,
const Vector other2 
) const

Computes the cross product, interpreting all vectors as 4D vectors.

Parameters
other1The vector to compute the product with.
other2The vector to compute the product with.
Returns
The resulting cross product computed.

◆ getLength()

float nkMaths::Vector::getLength ( ) const
Returns
The length of the vector.

◆ getLengthSquared()

float nkMaths::Vector::getLengthSquared ( ) const
Returns
The length of the vector, quared. For simple comparisons, if possible, prefer this function as it is more performant.

◆ getDistanceSquared()

float nkMaths::Vector::getDistanceSquared ( const Vector other) const
Parameters
otherThe vector to check the distance with.
Returns
The distance between both vectors, squared. Prefer to use this function when possible as it is more performant.

◆ getDistance()

float nkMaths::Vector::getDistance ( const Vector other) const
Parameters
otherThe vector to check the distance with.
Returns
The distance between both vectors.

◆ fromString()

void nkMaths::Vector::fromString ( const std::string_view &  str)

Parse components from a string. Format is "x,y,z,w".

Parameters
strThe string to parse.

◆ operator=() [1/2]

Vector& nkMaths::Vector::operator= ( const Vector other)

Assignment operator.

Parameters
otherThe vector to overwrite from.
Returns
The calling vector, updated.

◆ operator=() [2/2]

Vector& nkMaths::Vector::operator= ( const IVector other)

Assignment operator.

Parameters
otherThe vector to overwrite from.
Returns
The calling vector, updated.

◆ operator+()

Vector nkMaths::Vector::operator+ ( const Vector other) const

Addition operator.

Parameters
otherThe vector to operate with.
Returns
A result vector, after operation application.

◆ operator+=()

void nkMaths::Vector::operator+= ( const Vector other)

Addition and assignment operator.

Parameters
otherThe vector to operate with.

◆ operator-()

Vector nkMaths::Vector::operator- ( const Vector other) const

Subtraction operator.

Parameters
otherThe vector to operate with.
Returns
A result vector, after operation application.

◆ operator-=()

void nkMaths::Vector::operator-= ( const Vector other)

Subtraction and assignment operator.

Parameters
otherThe vector to operate with.

◆ operator*() [1/4]

Vector nkMaths::Vector::operator* ( const Vector other) const

Multiplication operator.

Parameters
otherThe vector to operate with.
Returns
A result vector, after operation application.

◆ operator*=() [1/4]

void nkMaths::Vector::operator*= ( const Vector other)

Multiplication and assignment operator.

Parameters
otherThe vector to operate with.

◆ operator*() [2/4]

Vector nkMaths::Vector::operator* ( const Quaternion other) const

Multiplication operator.

Parameters
otherThe quaternion to operate with.
Returns
A result vector, after transformation.

◆ operator*=() [2/4]

void nkMaths::Vector::operator*= ( const Quaternion other)

Multiplication and assignment operator.

Parameters
otherThe quaternion to operate with.

◆ operator*() [3/4]

Vector nkMaths::Vector::operator* ( const Matrix mat) const

Multiplication operator.

Parameters
matThe matrix to operate with.
Returns
A result vector, after transformation.

◆ operator*=() [3/4]

void nkMaths::Vector::operator*= ( const Matrix other)

Multiplication and assignment operator.

Parameters
otherThe matrix to operate with.

◆ operator*() [4/4]

Vector nkMaths::Vector::operator* ( float  coeff) const

Multiplication operator.

Parameters
coeffThe scalar to operate with.
Returns
A result vector, after operation application on all components.

◆ operator*=() [4/4]

void nkMaths::Vector::operator*= ( float  coeff)

Multiplication and assignment operator.

Parameters
coeffThe scalar to operate with.

◆ operator/() [1/2]

Vector nkMaths::Vector::operator/ ( const Vector other) const

Division operator.

Parameters
otherThe vector to operate with.
Returns
A result vector, after operation application.

◆ operator/=() [1/2]

void nkMaths::Vector::operator/= ( const Vector other)

Division and assignment operator.

Parameters
otherThe vector to operate with.

◆ operator/() [2/2]

Vector nkMaths::Vector::operator/ ( float  coeff) const

Division operator.

Parameters
coeffThe scalar to operate with.
Returns
A result vector, after operation application on all components.

◆ operator/=() [2/2]

void nkMaths::Vector::operator/= ( float  coeff)

Division and assignment operator.

Parameters
coeffThe scalar to operate with.

◆ operator==()

bool nkMaths::Vector::operator== ( const Vector other) const

Equality operator.

Parameters
otherThe vector to check against.
Returns
If the vectors are equal (true) or not (false).

◆ operator!=()

bool nkMaths::Vector::operator!= ( const Vector other) const

Difference operator.

Parameters
otherThe vector to check against.
Returns
If the vectors are different (true) or not (false).

◆ operator<()

bool nkMaths::Vector::operator< ( const Vector other) const

Less than operator.

Parameters
otherThe vector to check against.
Returns
If the calling vector is smaller (true) or not (false).

◆ operator<=()

bool nkMaths::Vector::operator<= ( const Vector other) const

Less than or equal operator.

Parameters
otherThe vector to check against.
Returns
If the calling vector is smaller, equal (true) or not (false).

◆ operator>()

bool nkMaths::Vector::operator> ( const Vector other) const

Greater than operator.

Parameters
otherThe vector to check against.
Returns
If the calling vector is greater (true) or not (false).

◆ operator>=()

bool nkMaths::Vector::operator>= ( const Vector other) const

Greater than or equal operator.

Parameters
otherThe vector to check against.
Returns
If the calling vector is greater, equal (true) or not (false).

The documentation for this class was generated from the following file: